package com.lz.homedecoration.common.service.impl;

import com.lz.homedecoration.common.bean.PageResult;
import com.lz.homedecoration.common.dao.BaseDao;
import com.lz.homedecoration.common.request.PageReq;
import com.lz.homedecoration.common.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

public class BaseServiceImpl<T, PK extends Serializable> implements BaseService<T, PK> {
    @Autowired
    BaseDao<T, PK> baseDao;

    public List<T> list() { return baseDao.list(); }
    @Override
    public T get(PK id) {
        return (T) baseDao.get(id);
    }

    @Override
    public int add(T t) {
        return baseDao.add(t);
    }

    @Override
    public int delete(PK id) {
        return baseDao.delete(id);
    }

    @Override
    public int update(T t) {
        return baseDao.update(t);
    }

    @Override
    public PageResult<T> pageList(PageReq<T> pageReq) {
        PageResult<T> pageResult = new PageResult<T>();
        pageResult.setList(baseDao.page(pageReq));
        long count = baseDao.count(pageReq);
        pageResult.setCount(count);
        return pageResult;
    }


}
